package com.atguigu.cloud.controller;

import com.atguigu.cloud.entities.Pay;
import com.atguigu.cloud.resp.ResultData;
import com.atguigu.cloud.service.PayService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @Author liking
 * @Description
 * @Date 2025/4/24
 * @Version 1.0
 */
@RestController
@RequestMapping("/pay")
public class FeignConnectTimeOutController {

    @Resource
    private PayService payService;

    @GetMapping("/connectTimeOut")
    public ResultData<Pay> connectTimeOut() {
        try {
            // 模拟超时 62s
            TimeUnit.SECONDS.sleep(62);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        Pay payById = payService.getPayById(1);
        if (payById == null) {
            return ResultData.fail("404","没有找到对应的支付流水");
        }
        return ResultData.success(payById);
    }

}
